#include <stdio.h>
#include<assert.h>
#include<getopt.h>
#include "../include/menu.h"

static void testEncryption(void);
static void testNoIn(void);
static void testNoOut(void);
static void testIfPasswordNoKey(void);
static void testEncryptionAndDecryption(void);
static void testNoOperation(void);
static void testNoAlgorithm(void);
static void testNoMethod(void);

int
main( void ) 
{
    /*
    ** We use optind to restart getopt status.
    ** http://stackoverflow.com/questions/535792/command-line-processing-library-getopt
    */

    testEncryption();
    optind=1;

    testNoIn();
    optind=1;

    testNoOut();
    optind=1;

    testIfPasswordNoKey();
    optind=1;

    testEncryptionAndDecryption();
    optind=1;

    testNoOperation();
    optind=1;

    testNoAlgorithm();
    optind=1;

    testNoMethod();
    optind=1;

    return 1;
}

static void
testEncryption(void) {
    char *argv[] = {"appName", "-e", "-i", "in.bmp", "-o", "out.bmp", "-p",
                    "password", "-a", "des", "-m", "ecb"};
    int argc = 12;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 1 );
    freeParameters(&params);
}

static void
testNoIn(void) {
    char *argv[] = {"appName", "-e", "-o", "out.bmp", "-p",
                    "password", "-a", "des", "-m", "ecb"};
    int argc = 10;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}

static void
testNoOut(void) {
    char *argv[] = {"appName", "-e", "-i", "in.bmp", "-p",
                    "password", "-a", "des", "-m", "ecb"};
    int argc = 10;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}

static void
testIfPasswordNoKey(void) {
    char *argv[] = {"appName", "-e", "-i", "in.bmp", "-o", "out.bmp", "-p",
                    "password", "-k", "key", "-a", "des", "-m", "ecb"};
    int argc = 14;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}

static void
testEncryptionAndDecryption(void) {
    char *argv[] = {"appName", "-e", "-d", "-i", "in.bmp", "-o", "out.bmp", "-p",
                    "password", "-a", "des", "-m", "ecb"};
    int argc = 13;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}

static void
testNoOperation(void) {
    char *argv[] = {"appName", "-i", "in.bmp", "-o", "out.bmp", "-p",
                    "password", "-a", "des", "-m", "ecb"};
    int argc = 11;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}

static void
testNoAlgorithm(void) {
    char *argv[] = {"appName", "-e", "-i", "in.bmp", "-o", "out.bmp", "-p",
                    "password", "-m", "ecb"};
    int argc = 10;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}

static void
testNoMethod(void) {
    char *argv[] = {"appName", "-e", "-i", "in.bmp", "-o", "out.bmp", "-p",
                    "password", "-a", "des"};
    int argc = 10;
    appInit params;
    getParameters(argc, argv, &params);
    assert( validateParameters(&params) == 0 );
    freeParameters(&params);
}


